package com.idcard.huashi;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.msd.ocr.idcard.LibraryInitOCR;
import com.zysoft.function.ApiUtil;
import com.zysoft.function.HorizontalProgressBarWithNumber;
import com.zysoft.function.Signature;
import com.zysoft.function.Stroage;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class IdcardFragment extends Activity implements OnClickListener {

	public HorizontalProgressBarWithNumber mProgressBar;
	public static final int MSG_PROGRESS_UPDATE = 0x110;
	public static final int OFFILNE_TEAM_SUCCESSD = 200;
	public static final int OFFILNE_PERSON_SUCCESSD = 201;
	public static final int OFFILNE__EXIT_SUCCESSD = 202;
	public static final int OFFILNE_FAILE = 203;
	public static final int ImageUrl_SUCCEED = 204;
	public static final int ImageUrl_FAILE = 205;
	public static  String HEADURL;

	private HashMap<String, Object> person;
	private HashMap<String,Object> urlList;
	private HashMap<String, Object> Uploadimg;
	private String flgid;
	private  ArrayList<JSONObject> PersonList;

	private static int isManually = 99;//是否手动输入
	private  int TempCode = 0;
	private  static final int IDCLERAD_FAILE = 199;//现场照片
	private  static final int LivePhotoCode = 1;//现场照片
	private  static final int IDPhotoCode = 2;//证件照片
	private  static final int ContractPhotoCode = 3;//合同照片
	private static final int MSG_SHOW_PROGRESS_DIALOG = 4;
	private static final int MSG_DISMISS_PROGRESS_DIALOG = 5;
	private static final int MSG_SHOW_ERROR = 6;
	private static final int MSG_SHOW_INFO = 7;
	private static final int SAM_SUCCEED = 8;
	private static final int READER_IDCARD_SUCCEED = 9;
	private static final int READER_IDCARD_FAILE= 10;
	private static final int PHOTO_SUCCEED = 11;
    private static final int SUCCEED = 12;
    private static final int FAILE = 13;
    private static final int JobType_SUCCEED = 14;
    private static final int JobType_FAILE = 15;
    private static final int WorkerType_SUCCEED = 16;
    private static final int WorkerType_FAILE = 17;

    private static final int SUBMIT_SUCCESSD = 18;
    private static final int SUBMIT_FAILE = 19;
    private static final int Fingerprint_Failure = 20;
    private static final int Fingerprint_SUCCEED = 21;
    private static final int MSG_UPDATE_IMAGE = 22;
    private static final int Fingeripint_ShowLoading = 23;
	private static final int Fingeripint_HideLoading = 24;
	private static final int Algorithm_Faile =25;
	//身份证头像
	private static final int HeadImageUrl_SUCCEED = 26;
	private static final int HeadImageUrl_FAILE = 27;
	//现场人员照片
	private static final int LiveImageUrl_SUCCEED = 28;
	private static final int LiveImageUrl_FAILE = 29;
	//指纹照片
	private static final int FingerprintUlr_SUCCEED = 30;
	private static final int FingerprintUrl_FAILE = 31;
	//证件照片
	private static final int CardUrl_SUCCEED = 32;
	private static final int CardUrl_FAILE = 33;
	//签名照片
	private static final int SignId_SUCCEED =34;
	private static final int SignId_FAILE = 35;
	//设备标识
    private static final int DEVICE_SUCCED = 36;
    private static final int DEVICE_FAILE = 37;
	private Context mCtx;

	private String headImageUrl = "";//身份证头像
	private String liveImageUrl = "";//现场图片
	private String fingerprintUrl = "";//指纹图片
	private String CardNewUrl = "";//证件照片
	private String signId = "";//手写签名图片
	private TextView LongID;//长期


	private ArrayList<String> InfoData;
    private ArrayList<String> WorkData;
	private ArrayList<String> JobeData;
    private ArrayList<String> IdentData;
    private ArrayList<String> DevcData;
    private ArrayList<String> InfoCode;
	private JSONArray WorkCode;
	private JSONArray JobeCode;
    private JSONArray IdentCode;

	private String InfoValue;
	private String WorkValue;
	private String JobeValue = "";
	private String IdentValue;
	private String Theteam = "0";

	private Map<String,String> MapData = null; // 声明Map对象，其中key和value的类型为String
	private ApiUtil apiUtil;

	private Alert alert;

	private TextView offline_data_submit;//离线提交数据
	private TextView update_data;//更新本地数据
	private TextView log_exit;//退出登录
	private TextView btn_center;//取消Alert
	private TextView Switch_project;//项目切换
	private TextView Staff_exit;//人员退场
	private TextView data_entry;//数据录入
	private TextView Power_off;//设备断电
	private TextView depart_data;//班组部门

	//基本信息
    private EditText Remarks;
	private TextView title_project;
	private EditText name;//姓名
	private RadioGroup sexgroup;// 性别
	private RadioGroup historyGroup;//病史
	private RadioGroup rylx;
	private RadioGroup isSpecialWorkTyp;
	private RadioGroup zt;
	private RadioGroup whether;//班组长
	private RadioButton sexRadio1;//性别 男
	private RadioButton sexRadio2;// 性别 女
	private EditText nationality;//民族
	private EditText brith;//出生地
	private EditText type_of_cert;//出生日期
	private EditText sfzhm;//身份证号码
	private EditText timeStart;//有效日期开始
	private EditText expiryTime;//有效日期结束
	private EditText authority;//签发机关
	private EditText adder;//家庭住址
	private ImageView fingerprint;//指纹
	private ImageView newCard;//现场照片
	private EditText blood_group;//血型
	private ImageView card;
	private EditText phone;//联系电话
	private TextView clear;//清除签名
	private TextView save;//保存签名
	private TextView signa_center;//取消签名
    private TextView isText;
	private Stroage stroage;
	private Util util;
	private Signature mPathView;
	private String sex;//性别
	private String SpecialWorkTyp;//特种工种
	private String fault;//病史
	private String Person_Type;//人员类型
	private String status;//状态

	private Context context;

	//劳务信息
	private EditText bzbm;//班组/部门
	private EditText gz;//工种
	private EditText gwlx;//岗位类型
	private EditText jcrq;// 进场日期
	private EditText sbbh;// 设备编号
	private ImageView photo;//身份证照片
	private ListView loop_list;
	private ListView dep_list;
	private ListView jobe_list;
	private ListView work_list;
	private ImageView Sign;

	private static final String TAG = "IdcardFragment";
	private static final String FP_DB_PATH = "/sdcard/fp.db";
	private SoundPool soundPool;
	private int mId;

	int version = Integer.parseInt(Build.VERSION.SDK);

	private ImageView iv_photo;
	private Button bt_readidcard;
	private SharedPreferences sp;
	static String filepath = "";
	private Uri uri;
	private static final String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/photo.jpg";
	private static final String  FINGER_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/zy.jpg";

	Date date = new Date();
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式yyyy-MM-dd//yyyy年MM月dd日

	public void creame(int code){
		Log.e("zysoft","相机获取code"+code);
		File file = new File(FILE_PATH);
		if (file.exists()) {
			file.delete();
		}
		// 把文件地址转换成Uri格式
		uri = Uri.fromFile(file);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		TempCode = code;
		startActivityForResult(intent,0);
	}
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode == RESULT_OK && requestCode == 99){//身份证识别成功
			String result = data.getStringExtra("OCRResult");
			Log.e("zysoft",result);
			try {
				JSONObject res = new JSONObject(result);
				if(res.getInt("type") == 0){
					type_of_cert.setText("身份证");
					authority.setText(res.getString("issue"));
					if(!res.getString("valid").equals("")){
					    int sub = res.getString("valid").length();
						timeStart.setText(res.getString("valid").substring(0,10).replace(".","-"));
						expiryTime.setText(res.getString("valid").substring(11,sub).replace(".","-"));
						if(!isDate(res.getString("valid").substring(11,sub).replace(".","-"))){
                            expiryTime.setText("长期");
                        }
					}
				}else {
					name.setText(res.getString("name"));
					RadioGroup xb = findViewById(R.id.Sexgroup);
					RadioButton boy = (RadioButton) sexgroup.getChildAt(0);
                    RadioButton gir = (RadioButton) sexgroup.getChildAt(1);
                    Log.e("zysoft",res.getString("sex"));
                    if(res.getString("sex").equals("男")){
                    	Log.e("zysoft","男");
                    	sex = "0";
//						xb.setId(R.id.SexRadio1);
//						xb.check(R.id.SexRadio1);
                        boy.setChecked(true);
                        gir.setChecked(false);
                    }else {
						sex = "1";
//						xb.setId(R.id.SexRadio2);
//						xb.check(R.id.SexRadio2);
						boy.setChecked(false);
						gir.setChecked(true);
						Log.e("zysoft","女");
					}
					nationality.setText(res.getString("folk"));
					if(!TextUtils.isEmpty(res.getString("birt"))){
                        brith.setText(res.getString("birt").replace("年","-").replace("月","-").replace("日",""));
                    }
					adder.setText(res.getString("addr"));
					sfzhm.setText(res.getString("num"));
					if(!TextUtils.isEmpty(res.getString("headPath"))){
						fingerprint.setImageBitmap(compressBySize(res.getString("headPath")));
						HEADURL = res.getString("headPath");
					}
					apiUtil.ShowLoading("图片上传中...",mCtx);
					Image(res.getString("headPath"),1);
				}
				DeteleImg(res.getString("imgPath"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		if(resultCode == RESULT_OK && requestCode == 0){
			try {
                Bitmap bitmap = (Bitmap)data.getExtras().get("data");
				switch (TempCode) {
					case 1:{
						Log.e("zysoft","现场照片");
						newCard.setImageBitmap(bitmap);
						saveFile(bitmap,FILE_PATH);//压缩后并保存图片
						apiUtil.ShowLoading("上传中...",mCtx);
						Image(FILE_PATH,2);
						break;
					}
					case 2:{
						Log.e("zysoft","证件照");
						photo.setImageBitmap(bitmap);
						saveFile(bitmap,FILE_PATH);// 压缩后并保存图片
						apiUtil.ShowLoading("上传中...",mCtx);
						Image(FILE_PATH,4);
						break;
					}
					case 3:{
						card.setImageBitmap(bitmap);
						saveFile(bitmap,FILE_PATH);// 压缩后并保存图片
						apiUtil.ShowLoading("上传中...",mCtx);
						Image(FILE_PATH,1);
						break;
					}
				}
			} catch (FileNotFoundException e) {
				e.getMessage();
				apiUtil.ShowToast("图片不存在，请重新拍照");

			} catch (IOException e) {
				apiUtil.ShowToast("图片不存在，请重新拍照");
				e.getMessage();
			}
		}
	}
	private static Bitmap compressBySize(String filepath){
		BitmapFactory.Options opts = new BitmapFactory.Options();
		opts.inSampleSize = 5;
		Bitmap bitmap = BitmapFactory.decodeFile(filepath, opts);
		return bitmap;
	}
	//保存压缩后的图片
	private void saveFile(Bitmap bitmap, String filePath2) throws IOException {
		// TODO Auto-generated method stub
		File testFile = new File(filePath2);
		if (testFile.exists()) {
			testFile.delete();
		}
		File myCaptureFile = new File(filePath2);
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
		// 100表示不进行压缩，70表示压缩率为30%
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);//PNG图片是无损的，不能进行压缩。
		bos.flush();
		bos.close();
		Log.e("zysoft",filePath2);
	}
	@SuppressLint("HandlerLeak")
	public final Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
				case SUBMIT_SUCCESSD:{
					Log.e("zysoft"+apiUtil.dateTime(),"离线数据上传日志信息"+msg.obj.toString());
					try {
						JSONObject json = new JSONObject(msg.obj.toString());
						if(json.has("code") && json.getInt("code") == 200){
							apiUtil.ShowToast("提交成功");
							isManually = 99;
							InitData();
						}else {
							apiUtil.ShowToast(json.getString("msg"));
						}
					} catch (JSONException e) {
						apiUtil.ShowToast("解析异常"+msg.obj.toString());
						e.printStackTrace();
					}
					apiUtil.HideLoading();
					break;
				}
				case SUBMIT_FAILE:{
					Log.e("zysoft"+apiUtil.dateTime(),"数据上传失败"+msg.obj.toString());
					apiUtil.HideLoading();
					apiUtil.ShowToast(msg.obj.toString());
					break;
				}
                case SUCCEED: {
					try {
						JSONObject json = new JSONObject(msg.obj.toString());
						if(json.has("code") && (json.getInt("code") == 200)){
							Teame(json.getString("data"));
						}else {
							apiUtil.ShowToast(json.getString("msg"));
						}
					} catch (JSONException e) {
						e.printStackTrace();
						Log.e("zysoft","解析失败");
						apiUtil.ShowToast("后台数据格式发生变化，需要重新解析");
					}
					apiUtil.HideLoading();
                    break;
                }
                case FAILE: {
                    apiUtil.ShowToast(msg.obj.toString());
                    apiUtil.HideLoading();
                    break;
                }
                case WorkerType_SUCCEED:{
					apiUtil.HideLoading();
					try {
						JSONObject json = new JSONObject(msg.obj.toString());
						if(json.has("code") && (json.getInt("code") == 200)){
							JSONObject js = json.getJSONObject("data");
							JSONArray WorkArry = js.getJSONArray("workerType");
							WorkCode = WorkArry;
                            WorkData = new ArrayList<String>();
							for(int i=0;i<WorkArry.length();i++){
								WorkData.add(WorkArry.getJSONObject(i).optString("text"));
							}
							util.ShowWork();

						}else {
							apiUtil.ShowToast(json.getString("msg"));
						}
					} catch (JSONException e) {
						e.printStackTrace();
						Log.e("zysoft","解析失败");
						apiUtil.ShowToast("后台数据格式发生变化，需要重新解析");
					}
					break;
                }
                case WorkerType_FAILE:{
                    apiUtil.ShowToast(msg.obj.toString());
					apiUtil.HideLoading();
                    break;
                }
                case JobType_SUCCEED:{
					try {
						JSONObject json = new JSONObject(msg.obj.toString());
						if(json.has("code") && (json.getInt("code") == 200)){
							JSONObject js = json.getJSONObject("data");
							JSONArray JobeArry = js.getJSONArray("jobType");
							JobeCode = JobeArry;
                            JobeData = new ArrayList<String>();
							for(int i=0;i<JobeArry.length();i++){
								JobeData.add(JobeArry.getJSONObject(i).optString("text"));
							}
							util.ShowJobe();
						}else {
							apiUtil.ShowToast(json.getString("msg"));
						}
					} catch (JSONException e) {
						e.printStackTrace();
						Log.e("zysoft","解析失败");
						apiUtil.ShowToast("后台数据格式发生改变，需要重新解析");
					}
					apiUtil.HideLoading();
                    break;
                }
                case JobType_FAILE:{
                    apiUtil.ShowToast(msg.obj.toString());
                    Log.e("zysoft",msg.obj.toString());
					apiUtil.HideLoading();
                    break;
                }
				case ImageUrl_FAILE:{
					alert.HideAlert();
					apiUtil.ShowToast((String)msg.obj);
				}
				case  HeadImageUrl_SUCCEED:{
					apiUtil.HideLoading();
					DeteleImg(HEADURL);
					try {
						JSONObject res = new JSONObject((String)msg.obj);
						if(res.has("resultCode") && res.getInt("resultCode") == 200){
							headImageUrl = res.getJSONArray("resultData").getJSONObject(0).getString("attaUrl");
							apiUtil.ShowToast("图片上传成功");
						}else {
							headImageUrl = "";
							apiUtil.ShowToast("图片上传失败，请重新拍照上传");
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
					break;
				}
				case HeadImageUrl_FAILE:{
					DeteleImg(HEADURL);
					apiUtil.HideLoading();
					apiUtil.ShowToast(msg.obj.toString());
					break;
				}
				case LiveImageUrl_SUCCEED:{//现场人员图片 liveImageUrl
					apiUtil.HideLoading();
					try {
						JSONObject res = new JSONObject((String)msg.obj);
						Log.e("zysoft",res.toString());
						if(res.has("resultCode") && res.getInt("resultCode") == 200){
							apiUtil.ShowToast("图片上传成功");
							liveImageUrl = res.getJSONArray("resultData").getJSONObject(0).getString("attaUrl");
							DeteleImg(FILE_PATH);
						}else {
							liveImageUrl="";
							apiUtil.ShowToast("图片上传失败,请重新拍照上传");
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
					break;
				}
				case LiveImageUrl_FAILE:{
					apiUtil.HideLoading();
					apiUtil.ShowToast((String) msg.obj);
					break;
				}
				case CardUrl_SUCCEED:{//身份证证件照片 CardNewUrl
					try {
						JSONObject res = new JSONObject((String)msg.obj);
						if(res.has("resultCode") && res.getInt("resultCode") == 200){
							apiUtil.ShowToast("图片上传成功");
							CardNewUrl = res.getJSONArray("resultData").getJSONObject(0).getString("attaUrl");
							Log.e("zysoft",CardNewUrl);
							DeteleImg(FILE_PATH);
						}else {
							CardNewUrl ="";
							apiUtil.ShowToast("证件照片上传失败请重新拍照上传");
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
					apiUtil.HideLoading();
					break;
				}
				case CardUrl_FAILE:{
					apiUtil.HideLoading();
					apiUtil.ShowToast("身份证上传失败");
					break;
				}
				case SignId_SUCCEED:{//签名图片signId
					try {
						JSONObject res = new JSONObject((String)msg.obj);
						if(res.has("resultCode") && res.getInt("resultCode") == 200){
							apiUtil.ShowToast("签名上传成功");
							signId = res.getJSONArray("resultData").getJSONObject(0).getString("attaUrl");
							DeteleImg(FINGER_PATH);
						}else {
							signId ="";
							apiUtil.ShowToast("签名上传失败，请重新上传");
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
					apiUtil.HideLoading();
					break;
				}
				case SignId_FAILE:{
					apiUtil.HideLoading();
					apiUtil.ShowToast("签名上传失败");
					break;
				}
				case IDCLERAD_FAILE:{
					apiUtil.ShowToast(msg.obj.toString());
					break;
				}
				case PHOTO_SUCCEED: {
					try {
						FileInputStream fis = new FileInputStream(filepath + "/zp.bmp");
						Bitmap bmp = BitmapFactory.decodeStream(fis);
						fis.close();
						card.setImageBitmap(bmp);
						if(stroage.getState(mCtx).toString().equals("0")){
							saveBitmapFile(bmp,1);
						}else {
							headImageUrl = "身份证头像";
						}
					} catch (FileNotFoundException e) {
						showInfoToast("头像不存在");
					} catch (IOException e) {
						// TODO 自动生成的 catch 块
						showInfoToast("头像读取失败");
					} catch (Exception e) {
						showInfoToast("头像解码失败");
					}
					break;
				}
			}
		}
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.e(TAG,"onCreate");
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏 使用自定义标题栏;
		if (Build.VERSION.SDK_INT >= 21) {//21表示5.0
			Window window = getWindow();
			window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
			window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			window.setStatusBarColor(Color.TRANSPARENT);
		}
		mCtx = this;
		context = this;
		stroage = new Stroage();
		util = new Util();
		alert = new Alert();
		apiUtil = new ApiUtil();
		initView();
		initEvent();
	}
	private void initView() {
//		AndPermission.with(mCtx).runtime().permission(Permission.Group.CAMERA, Permission.Group.STORAGE).start();//相机授权
		setContentView(R.layout.fragment_form);
		View show =findViewById(R.id.img_btn);
		View back =findViewById(R.id.img_back);
		show.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				alert.ShowAlert();
			}
		});
		back.setVisibility(View.VISIBLE);
		back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				Log.e("zysoft","你点击了回退按钮");
				Intent intent = new Intent(mCtx, ProjectFragment.class);
				startActivity(intent);
				finish();
			}
		});
		LongID = findViewById(R.id.LongID);
//		title_project = findViewById(R.id.title_project);
//		title_project.setText(stroage.getName(mCtx).toString());
		card =  findViewById(R.id.card);//身份证头像
		bt_readidcard = findViewById(R.id.log_btn);//数据提交
		name = findViewById(R.id.name);//姓名
		Remarks = findViewById(R.id.Remarks);//备注
		isText =  findViewById(R.id.isText);
		fingerprint = findViewById(R.id.card);
		sexgroup = findViewById(R.id.Sexgroup);
		historyGroup = findViewById(R.id.historyGroup);
		rylx = findViewById(R.id.rylx);
		whether = findViewById(R.id.whether);
		isSpecialWorkTyp = findViewById(R.id.isSpecialWorkTyp);
		zt = findViewById(R.id.zt);

		sexRadio1 = findViewById(R.id.SexRadio1);//性别 男
		sexRadio2 =findViewById(R.id.SexRadio2);// 性别 女
		nationality = findViewById(R.id.Nationality);//民族
		brith = findViewById(R.id.brith);//出生日期
		type_of_cert =findViewById(R.id.Type_of_cert);//证件类型
		sfzhm = findViewById(R.id.sfzhm);//身份证号码
		timeStart = findViewById(R.id.startTime);//有效日期开始
		expiryTime =findViewById(R.id.expiryTime);//有效日期开始
		authority = findViewById(R.id.authority);//签发机关
		adder = findViewById(R.id.adder);//家庭住址
		phone = findViewById(R.id.phone);//联系电话
		sbbh = findViewById(R.id.sbbh);//设备标识
		jcrq = findViewById(R.id.jcrq);//进长日期
		blood_group = findViewById(R.id.blood_group);//血型
		jcrq.setText(df.format(date));//进场日期

		bzbm = findViewById(R.id.bzbm);//班组部门
		gz = findViewById(R.id.gz);//工种
		gwlx = findViewById(R.id.gwlx);//岗位类型
		sexgroup = findViewById(R.id.Sexgroup); // 性别
		newCard = findViewById(R.id.newCard);// 现场照片
		photo = findViewById(R.id.idPhoto);//证件照片
		Sign = findViewById(R.id.SignPhoto);//签名
	}
	public void initEvent(){
		blood_group.setOnClickListener(this);
		bzbm.setOnClickListener(this);
		gz.setOnClickListener(this);
		gwlx.setOnClickListener(this);
		LongID.setOnClickListener(this);
		card.setOnClickListener(this);
		newCard.setOnClickListener(this);
		photo.setOnClickListener(this);
		Sign.setOnClickListener(this);
		jcrq.setOnClickListener(this);
		brith.setOnClickListener(this);
		timeStart.setOnClickListener(this);
		expiryTime.setOnClickListener(this);
		bt_readidcard.setOnClickListener(this);
		whether.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {//是否为班组长
			@Override
			public void onCheckedChanged(RadioGroup radioGroup, int i) {
				switch (i){
					case R.id.isRadio1:
						Log.e("zysoft","你选择了是");
						Theteam = "1";
						break;
					case R.id.isRadio2:
						Log.e("zysoft","你选择了否");
						Theteam = "0";
						break;
				}
			}
		});
		historyGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup radioGroup, int i) {
				switch (i){
					case R.id.historyRadio1:
						Log.e("zysoft","你选择了是");
						Remarks.setVisibility(View.VISIBLE);
						isText.setVisibility(View.VISIBLE);
						break;
					case R.id.historyRadio2:
						Log.e("zysoft","你选择了否");
						Remarks.setVisibility(View.GONE);
						isText.setVisibility(View.GONE);
						break;
				}
			}
		});
	}
	@Override
	public void onClick(View view) {
		switch (view.getId()){
			case R.id.LongID:{
				expiryTime.setText("长期");
				break;
			}
			case R.id.blood_group:{
				util.ShowGroup();
				break;
			}
            case R.id.jcrq:{
                apiUtil.ShowDate(mCtx,jcrq,4);
                break;
            }
			case  R.id.brith:{
				apiUtil.ShowDate(mCtx,brith,3);
				break;
			}
			case  R.id.startTime:{
				apiUtil.ShowDate(mCtx,timeStart,1);
				break;
			}
			case  R.id.expiryTime:{
				apiUtil.ShowDate(mCtx,expiryTime,2);
				break;
			}
			case R.id.bzbm:
				Log.e("zysoft","班组");
				apiUtil.ShowLoading("请求中...",mCtx);
				Post(apiUtil.DepartTeam,stroage.getCode(mCtx).toString(),1);
				break;
            case R.id.gz:
                Log.e("zysoft","工种");
                apiUtil.ShowLoading("请求中...",mCtx);
                Ajax(apiUtil.DictionaryItem,2);
                break;
            case R.id.gwlx:
                Log.e("zysoft","岗位类型");
                apiUtil.ShowLoading("请求中...",mCtx);
                Ajax(apiUtil.DictionaryItem,3);
                break;
			case R.id.card:
				Log.e("zysoft","点击了信息识别");
				Bundle bundle = new Bundle();
				LibraryInitOCR.initOCR(context);
				bundle.putBoolean("saveImage", true);
				bundle.putInt("requestCode",99);
				bundle.putInt("type", 0); //0身份证, 1驾驶证
				LibraryInitOCR.startScan(context, bundle);
				break;
			case R.id.newCard:
				Log.e("zysoft","现场照片执行相机传参："+LivePhotoCode);
				creame(LivePhotoCode);
				break;
			case R.id.idPhoto:
				Log.e("zysoft","证件照执行相机传参："+IDPhotoCode);
				creame(IDPhotoCode);
				break;
			case R.id.SignPhoto:
				util.ShowSign();
				break;
				case  R.id.log_btn:{
				    Submit();
                }
		}

	}
	public void Teame(String data){
		JSONObject js = null;
		try {
			js = new JSONObject(data);
			Log.e("zysoft",js.toString());
			JSONArray InfoArry = js.getJSONArray("children");
			InfoCode = new ArrayList<String>();
			InfoData = new ArrayList<String>();
			if(InfoArry.length() == 0){
				apiUtil.HideLoading();
				apiUtil.ShowToast("暂无数据，请联系后台人员");
				return;
			}
			for(int i=0;i<InfoArry.length();i++){//项目下面的分包商
				JSONArray work = InfoArry.getJSONObject(i).getJSONArray("children");//某一分包商下面的作业队
				for(int j =0;j<work.length();j++){
					JSONArray team = work.getJSONObject(j).getJSONArray("children");//某一作业队下面的数组
					Log.e("zysoft", String.valueOf(team));
					for(int k = 0;k<team.length();k++){
						InfoData.add(work.getJSONObject(j).getString("name")+"——"+team.getJSONObject(k).optString("name"));
						InfoCode.add(team.getJSONObject(k).optString("id"));
					}
				}
			}
			util.ShowAlert();
		} catch (JSONException e) {
			apiUtil.ShowToast("数据解析失败");
			e.printStackTrace();
		}

	}
	//获取数据
	public void Submit(){
		RadioButton xb = (RadioButton) sexgroup.getChildAt(0);
		RadioButton hiso = (RadioButton) historyGroup.getChildAt(0);
		RadioButton lx = (RadioButton) rylx.getChildAt(0);
		RadioButton sta = (RadioButton) zt.getChildAt(0);
		RadioButton is = (RadioButton) isSpecialWorkTyp.getChildAt(0);
		//性别
		if(xb.isChecked()){
			sex = "0";
		}else {
			sex = "1";
		}
		//病史
		if(hiso.isChecked()){
			fault = "1";
		}else {
			fault = "0";
			Remarks.setText("");
		}
		//人员类型
		if(lx.isChecked()){
			Person_Type = "1";
		}else {
			Person_Type = "2";
		}
		//是否为特种工种
		if(is.isChecked()){
			SpecialWorkTyp = "1";
		}else {
			SpecialWorkTyp = "0";
		}
		//是否在岗
		if(sta.isChecked()){
			status = "1";
		}else {
			status = "0";
		}
		if(fault == "1" && TextUtils.isEmpty(Remarks.getText().toString().trim())){
            apiUtil.ShowToast("请输入病史原因");
            return;
        }
		 if(TextUtils.isEmpty(name.getText().toString().trim())){
		 	apiUtil.ShowToast("姓名不能为空");
		 	return;
		 }
		if(TextUtils.isEmpty(nationality.getText().toString().trim())){
			apiUtil.ShowToast("名族不能为空");
			return;
		}
		if(TextUtils.isEmpty(brith.getText().toString().trim())){
			apiUtil.ShowToast("出生日期不能为空");
			return;
		}
		if(TextUtils.isEmpty(timeStart.getText().toString().trim())){
			apiUtil.ShowToast("证件起始有效期不能为空");
			return;
		}
		if(TextUtils.isEmpty(expiryTime.getText().toString().trim())){
			apiUtil.ShowToast("证件截至有效期不能为空");
			return;
		}
		if(TextUtils.isEmpty(sfzhm.getText().toString().trim())){
			apiUtil.ShowToast("身份证号码不能为空");
			return;
		}
		if(TextUtils.isEmpty(authority.getText().toString().trim())){
			apiUtil.ShowToast("签发机关不能为空");
			return;
		}
		if(TextUtils.isEmpty(adder.getText().toString().trim())){
			apiUtil.ShowToast("家庭住址不能为空");
			return;
		}
		if(!isMobile(phone.getText().toString())){
			apiUtil.ShowToast("联系电话不合法");
			return;
		}
		if(TextUtils.isEmpty(blood_group.getText().toString().trim())){
			apiUtil.ShowToast("血型不能为空");
			return;
		}
		if(TextUtils.isEmpty(bzbm.getText().toString().trim())){
			apiUtil.ShowToast("班组不能为空");
			return;
		}
		if(TextUtils.isEmpty(gz.getText().toString().trim())){
			apiUtil.ShowToast("工种不能为空");
			return;
		}
		if(TextUtils.isEmpty(gwlx.getText().toString().trim())){
			apiUtil.ShowToast("岗位类型不能为空");
			return;
		}
		if(TextUtils.isEmpty(jcrq.getText().toString().trim())){
			apiUtil.ShowToast("进场日期不能为空");
			return;
		}
//		if(TextUtils.isEmpty(sbbh.getText().toString().trim())){
//			apiUtil.ShowToast("设备标识不能为空");
//			return;
//		}
		if(sbbh.getText().toString().trim().length()>16){
			apiUtil.ShowToast("设备标识不合法，长度控制在16位以内");
			return;
		}
		if(isManually == 100 && TextUtils.isEmpty(headImageUrl)){
			apiUtil.ShowToast("身份证照片不能为空");
			return;
		}
//		if(TextUtils.isEmpty(liveImageUrl)){
//			apiUtil.ShowToast("现场照片不能为空");
//			return;
//		}
//		if(TextUtils.isEmpty(fingerprintUrl)){
//			apiUtil.ShowToast("指纹照片不能为空");
//			return;
//		}
//		if(TextUtils.isEmpty(CardNewUrl)){
//			apiUtil.ShowToast("证件照片不能为空");
//			return;
//		}
//		if(TextUtils.isEmpty(signId)){
//			apiUtil.ShowToast("签名照片不能为空");
//			return;
//		}
        if(!isDate(timeStart.getText().toString())){
            apiUtil.ShowToast("身份证起始日期不合法 日期为："+timeStart.getText().toString());
            return;
        }
		apiUtil.ShowLoading("提交中...",mCtx);
		SubmitData();
	}
	public void SubmitData(){
		HashMap<String, Object> ok = new HashMap<String, Object>();
		ok.put("corpCode",stroage.getProcode(mCtx).toString());//公司编码
		ok.put("name",name.getText().toString());//姓名
		ok.put("gender",sex);//性别
		ok.put("nation",nationality.getText().toString());//民族
		ok.put("birthDay",brith.getText().toString());//出生日期
		ok.put("idCardType","01");//身份类型
		ok.put("idCardNumber",sfzhm.getText().toString().trim());//身份证号码//sfzhm.getText().toString()
		ok.put("startTime",timeStart.getText().toString());//身份证起始时间
		ok.put("expiryTime",expiryTime.getText().toString());//身份证介绍时间
		ok.put("grantOrg",authority.getText().toString());//签发机关
		ok.put("birthPlaceCode",sfzhm.getText().toString().substring(0,6));//籍贯
		ok.put("address",adder.getText().toString());//家庭住址
		ok.put("cellPhone",phone.getText().toString());//联系电话
		ok.put("hasBadMedicalHistory",fault);//重大病史
		ok.put("medicalHistory",Remarks.getText().toString());
		ok.put("status",status);//状态
		ok.put("headImageUrl",headImageUrl);//身份证头像
		ok.put("liveImageUrl",liveImageUrl);//现场图片
		ok.put("fingerprint","");//指纹图片
		ok.put("idCardImageUrl",CardNewUrl);//现场证件照片
		ok.put("signId",signId);//手写签名图片
		ok.put("bloodType",blood_group.getText().toString());//血型
		ok.put("workerType",Person_Type);//人员类别
		ok.put("workClassId",InfoValue);//班组id
		ok.put("isTeamLeader",Theteam);//是否为班组长
		ok.put("workTypeCode",WorkValue);//工种
		ok.put("isSpecialWorkType",SpecialWorkTyp);//特种工种
		ok.put("jobType",JobeValue);//岗位类型
		ok.put("entryTime",jcrq.getText().toString());//入场时间
		ok.put("type","4");//设备类型
		ok.put("productCode",sbbh.getText().toString().trim());//设备标识
		ok.put("projectCode",stroage.getCode(mCtx).toString());//项目编码
		Log.e("zysoft","数据上传参数："+ ok.toString());
		OkHttpClient client = new OkHttpClient.Builder()
				.connectTimeout(20, TimeUnit.SECONDS)//连接超时时间
				.readTimeout(20,TimeUnit.SECONDS)//读取超时时间;//创建OkHttpClient对象。
				.build();
		RequestBody requestBody = new FormBody.Builder()
				.add("corpCode",stroage.getProcode(mCtx).toString())//公司编码
				.add("name",name.getText().toString())//姓名
				.add("gender",sex)//性别
				.add("nation",nationality.getText().toString())//民族
				.add("birthDay",brith.getText().toString())//出生日期
				.add("idCardType","01")//身份类型
				.add("idCardNumber",sfzhm.getText().toString().trim())//身份证号码//sfzhm.getText().toString()
				.add("startTime",timeStart.getText().toString())//身份证起始时间
				.add("expiryTime",expiryTime.getText().toString())//身份证介绍时间
				.add("grantOrg",authority.getText().toString())//签发机关
				.add("birthPlaceCode",sfzhm.getText().toString().substring(0,6))//籍贯
				.add("address",adder.getText().toString())//家庭住址
				.add("cellPhone",phone.getText().toString())//联系电话
				.add("hasBadMedicalHistory",fault)//重大病史
				.add("medicalHistory",Remarks.getText().toString())
				.add("status",status)//状态
				.add("headImageUrl",headImageUrl)//身份证头像
				.add("liveImageUrl",liveImageUrl)//现场图片
				.add("fingerprint","")//指纹图片
				.add("idCardImageUrl",CardNewUrl)//现场证件照片
				.add("signId",signId)//手写签名图片
				.add("bloodType",blood_group.getText().toString())//血型
				.add("workerType",Person_Type)//人员类别
				.add("workClassId",InfoValue)//班组id
				.add("isTeamLeader",Theteam)//是否为班组长
				.add("workTypeCode",WorkValue)//工种
				.add("isSpecialWorkType",SpecialWorkTyp)//特种工种
				.add("jobType",JobeValue)//岗位类型
				.add("entryTime",jcrq.getText().toString())//入场时间
				.add("type","4")//设备类型
				.add("productCode",sbbh.getText().toString().trim())//设备标识
				.add("projectCode",stroage.getCode(mCtx).toString())//项目编码
				.build();
		Request request = new Request.Builder()
				.url(apiUtil.SubmitData)
				.post(requestBody)
				.build();
		client.newCall(request).enqueue(new Callback() {
			@Override
			public void onResponse(Call call, Response response) throws IOException {
				mHandler.sendMessage(mHandler.obtainMessage(SUBMIT_SUCCESSD, response.body().string()));
			}
			@Override
			public void onFailure(Call call, IOException e) {
				Log.d("zysoft", "onFailure: " + e.getMessage());
				if(e instanceof SocketTimeoutException){
					mHandler.sendMessage(mHandler.obtainMessage(SUBMIT_FAILE, "请求超时"));
				}else {
					mHandler.sendMessage(mHandler.obtainMessage(SUBMIT_FAILE, "连接异常"));
				}
			}
		});
	}
	//检测手机号是否合法
	public static boolean isMobile(String mobile){
		Pattern pattern =Pattern.compile("^(1[3-9][0-9])\\d{8}$");
		Matcher matcher=pattern.matcher(mobile);
		return matcher.matches();
	}
    //检测日期是否合法
    public static boolean isDate(String str){
        Pattern pattern =Pattern.compile("^(\\d{4})-(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])$");
        Matcher matcher=pattern.matcher(str);
        return matcher.matches();
    }
	public void saveBitmapFile(Bitmap bitmap,int i) {
		File file=new File(FINGER_PATH);//将要保存图片的路径
		try {
			BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
			bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
			bos.flush();
			bos.close();
			apiUtil.ShowLoading("上传中...",mCtx);
			Image(FINGER_PATH,i);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void DeteleImg(String url){
		File file = new File(url);
		if(file.exists()){
			Log.e("zysoft","图片删除");
			file.delete();
		}
	}
	//图片上传
	public void Image(String url,final int i){
		File file = new File(url);
		OkHttpClient client = new OkHttpClient.Builder()//创建OkHttpClient对象。
				.connectTimeout(20, TimeUnit.SECONDS)//连接超时时间
				.readTimeout(20,TimeUnit.SECONDS)//读取超时时间
				.build();
		RequestBody img = RequestBody.create(MediaType.parse("image/png"), file);
		RequestBody requestBody = new MultipartBody.Builder()
				.setType(MultipartBody.FORM)
				.addFormDataPart("upFile","photo.png",img)
				.addFormDataPart("attaId","0")
				.addFormDataPart("commTreeId","0")
				.addFormDataPart("attaDomain","penetrate")
				.addFormDataPart("domainId","100")
				.build();
		Request request = new Request.Builder()
				.url(apiUtil.ImageUrl)
				.post(requestBody)
				.build();
		client.newCall(request).enqueue(new Callback() {
			@Override
			public void onResponse(Call call, Response response) throws IOException {
				switch (i){
					case 1:
						mHandler.sendMessage(mHandler.obtainMessage(HeadImageUrl_SUCCEED, response.body().string()));
						break;
					case 2:
						mHandler.sendMessage(mHandler.obtainMessage(LiveImageUrl_SUCCEED, response.body().string()));
						break;
					case 3:
						mHandler.sendMessage(mHandler.obtainMessage(FingerprintUlr_SUCCEED, response.body().string()));
						break;
					case 4:
						mHandler.sendMessage(mHandler.obtainMessage(CardUrl_SUCCEED, response.body().string()));
						break;
					case 5:
						mHandler.sendMessage(mHandler.obtainMessage(SignId_SUCCEED, response.body().string()));
						break;
				}
			}
			@Override
			public void onFailure(Call call, IOException e) {
				if(e instanceof SocketTimeoutException){
					mHandler.sendMessage(mHandler.obtainMessage(FAILE, "请求超时"));
				}else {
					mHandler.sendMessage(mHandler.obtainMessage(FAILE, "连接异常"));
				}
			}
		});
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		Log.e(TAG, "onStart");
		super.onResume();
	}
	//初始化
	public void InitData(){
		fingerprint.setImageDrawable(getResources().getDrawable(R.drawable.ocr));//指纹
		newCard.setImageDrawable(getResources().getDrawable(R.drawable.newface));// 现场照片
		photo.setImageDrawable(getResources().getDrawable(R.drawable.idcard));//证件照片
		Sign.setImageDrawable(getResources().getDrawable(R.drawable.sign));//签名
		liveImageUrl = "";
		headImageUrl = "";
		fingerprintUrl = "";
		CardNewUrl = "";
		signId = "";
		phone.setText("");//电话号码
		sbbh.setText("");//设备编号
	}
	private void Post(String api,String code,final int i){//Map<String, String> params
		Log.e(apiUtil.dateTime(),code);
		OkHttpClient client = new OkHttpClient.Builder()//创建OkHttpClient对象。
				.connectTimeout(20, TimeUnit.SECONDS)//连接超时时间
				.readTimeout(20,TimeUnit.SECONDS)//读取超时时间
				.build();
		RequestBody requestBody = new FormBody.Builder()
				.add("projectCode",code)
				.build();
		Request request = new Request.Builder()
				.url(api)
				.post(requestBody)
				.build();
		client.newCall(request).enqueue(new Callback() {
			@Override
			public void onResponse(Call call, Response response) throws IOException {
				Log.d("zysoft", "responseCode" +"   " + response.code() + "responseMessage" + response.message());
				switch (i){
                    case 1:{
                        mHandler.sendMessage(mHandler.obtainMessage(SUCCEED, response.body().string()));
                        break;
                    }
                    case 2:{
                        mHandler.sendMessage(mHandler.obtainMessage(DEVICE_SUCCED, response.body().string()));
                        break;
                    }
                }
			}
			@Override
			public void onFailure(Call call, IOException e) {
				if(e instanceof SocketTimeoutException){
					mHandler.sendMessage(mHandler.obtainMessage(FAILE, "请求超时"));
				}else {
					mHandler.sendMessage(mHandler.obtainMessage(FAILE, "连接异常"));
				}
			}
		});
	}
    private void Ajax(String api, final int i){
        OkHttpClient client = new OkHttpClient.Builder()//创建OkHttpClient对象。
				.connectTimeout(20, TimeUnit.SECONDS)//连接超时时间
				.readTimeout(20,TimeUnit.SECONDS)//读取超时时间
				.build();
        RequestBody requestBody = new FormBody.Builder()
                .build();
        Request request = new Request.Builder()
                .url(api)
                .post(requestBody)
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("zysoft", "responseCode" +"   " + response.code() + "responseMessage" + response.message());
                switch (i){
                    case 1:
                        mHandler.sendMessage(mHandler.obtainMessage(SUCCEED, response.body().string()));
                        break;
                    case 2:
                        mHandler.sendMessage(mHandler.obtainMessage(WorkerType_SUCCEED, response.body().string()));
                        break;
                    case 3:
                        mHandler.sendMessage(mHandler.obtainMessage(JobType_SUCCEED, response.body().string()));
                        break;
                }
            }
            @Override
            public void onFailure(Call call, IOException e) {
            	Log.e("zysoft", String.valueOf(e));
				if(e instanceof SocketTimeoutException){
					switch (i){
						case 1:
							mHandler.sendMessage(mHandler.obtainMessage(FAILE, "请求超时"));
							break;
						case 2:
							mHandler.sendMessage(mHandler.obtainMessage(WorkerType_FAILE, "请求超时"));
							break;
						case 3:
							mHandler.sendMessage(mHandler.obtainMessage(JobType_FAILE, "请求超时"));
							break;
					}
				}else {
					switch (i){
						case 1:
							mHandler.sendMessage(mHandler.obtainMessage(FAILE, "请检查网络"));
							break;
						case 2:
							mHandler.sendMessage(mHandler.obtainMessage(WorkerType_FAILE, "请检查网络"));
							break;
						case 3:
							mHandler.sendMessage(mHandler.obtainMessage(JobType_FAILE, "请检查网络"));
							break;

					}
				}
            }
        });
    }
    public class Alert implements OnClickListener {

		Intent intent = new Intent(context,MainActivity.class);
		LayoutInflater inflater = LayoutInflater.from(mCtx);
		View show = inflater.inflate(R.layout.show_dialog, null);
		View confirm = inflater.inflate(R.layout.confirm, null);
		View progress = inflater.inflate(R.layout.progress_bar,null);//进度条
		AlertDialog.Builder builder = new AlertDialog.Builder(mCtx);
		Dialog dialog = builder.create();

		public void ShowPro(){
			dialog.show();
			Window window = dialog.getWindow();
			WindowManager.LayoutParams lp = window.getAttributes();
			WindowManager windowManager =getWindowManager();
			Display display = windowManager.getDefaultDisplay();
			lp.width = display.getWidth()-50;
			dialog.getWindow().setAttributes(lp);
			dialog.getWindow().setGravity(Gravity.CENTER);//可以设置显示的位置
			dialog.getWindow().setContentView(progress);//自定义布局应该在这里添加，要在dialog.show()的后面
			dialog.setCanceledOnTouchOutside(false);
			mProgressBar = (HorizontalProgressBarWithNumber) progress.findViewById(R.id.progressBar1);
			mHandler.sendMessage(mHandler.obtainMessage(MSG_PROGRESS_UPDATE,0));
		}

		public void ShowAlert(){
			dialog.show();
			Window window = dialog.getWindow();
			WindowManager.LayoutParams lp = window.getAttributes();
			WindowManager windowManager = getWindowManager();
			Display display = windowManager.getDefaultDisplay();
			lp.width = display.getWidth();
			dialog.getWindow().setAttributes(lp);
			dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
			dialog.getWindow().setContentView(show);//自定义布局应该在这里添加，要在dialog.show()的后面

			offline_data_submit = show.findViewById(R.id.offline_data_submit);//离线提交
			Switch_project = show.findViewById(R.id.Switch_project);//切换项目
			Staff_exit = show.findViewById(R.id.Staff_exit);//人员退场
			log_exit = show.findViewById(R.id.log_exit);//退出登录
			data_entry = show.findViewById(R.id.data_entry);//进场数据录入
			Power_off = show.findViewById(R.id.Power_off);//设备断电
			offline_data_submit.setVisibility(View.GONE);
			Power_off.setVisibility(View.GONE);
			data_entry.setVisibility(View.GONE);
			depart_data = show.findViewById(R.id.depart_data);//班组部门
			btn_center = show.findViewById(R.id.btn_center);//取消
			//监听事件
//			offline_data_submit.setOnClickListener(this);
			log_exit.setOnClickListener(this);
			Switch_project.setOnClickListener(this);
			Staff_exit.setOnClickListener(this);
			btn_center.setOnClickListener(this);
			data_entry.setOnClickListener(this);
			Power_off.setOnClickListener(this);
			depart_data.setOnClickListener(this);

		}
		public void HideAlert(){
			dialog.dismiss();
		}
		@Override
		public void onClick(View view) {
			switch (view.getId()){
				case R.id.depart_data:
					Log.e("zysoft","班组部门");
					HideAlert();
					Intent tem = new Intent(context,TeamFragment.class);
					startActivity(tem);
					finish();
					break;
				case R.id.Staff_exit:
					Log.e("zysoft","你点击了人员退场按钮");
					HideAlert();
					Intent exitPer = new Intent(context,StaffExitFragment.class);
					startActivity(exitPer);
					finish();
					break;
				case R.id.Switch_project:
					Log.e("zysoft","你点击了切换项目按钮");
					HideAlert();
					Intent intent = new Intent(context,ProjectFragment.class);
					startActivity(intent);
					break;
				case R.id.log_exit:
					Log.e("zysoft","你点击了退出当前项目按钮");
					HideAlert();
					Intent exit = new Intent(context,MainActivity.class);
					startActivity(exit);
					finish();
					break;
				case R.id.btn_center:
					Log.e("zysoft","你点击了取消按钮");
					HideAlert();
					break;
			}
		}
	}
	public class Util {
		LayoutInflater inflater = LayoutInflater.from(context);
		View loop = inflater.inflate(R.layout.activity_group,null);
		View depar = inflater.inflate(R.layout.department, null);
        View jobe = inflater.inflate(R.layout.jobe_type, null);
        View work = inflater.inflate(R.layout.work_type, null);
		View sign = inflater.inflate(R.layout.view, null);
		View iden = inflater.inflate(R.layout.activity_identity,null);
		AlertDialog.Builder builder = new AlertDialog.Builder(mCtx);
		Dialog dialog = builder.create();

		public void ShowGroup(){
			initLoop();
			dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
			dialog.show();
			Window window = dialog.getWindow();
			WindowManager.LayoutParams lp = window.getAttributes();
			WindowManager windowManager = getWindowManager();
			Display display = windowManager.getDefaultDisplay();
			lp.width = display.getWidth();
			dialog.getWindow().setAttributes(lp);
			dialog.getWindow().setContentView(loop);//自定义布局应该在这里添加，要在dialog.show()的后面

		}
		//设备标识
		public void ShowIdentity(){
            dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
            dialog.show();
            Window window = dialog.getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            WindowManager windowManager = getWindowManager();
            Display display = windowManager.getDefaultDisplay();
            lp.width = display.getWidth();
            dialog.getWindow().setAttributes(lp);
            dialog.getWindow().setContentView(iden);//自定义布局应该在这里添加，要在dialog.show()的后面
        }
		//签名
		public void ShowSign(){
            mPathView = sign.findViewById(R.id.view);
			clear = sign.findViewById(R.id.signa_clear);//清除按钮
			save = sign.findViewById(R.id.signa_save);//保存按钮
			signa_center = sign.findViewById(R.id.signa_center);
			clear.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View view) {
					mPathView.clear();
				}
			});
			save.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View view) {
					Log.e("zysoft","保存签名");
					Bitmap bitmap = mPathView.saveToBitmap(true, 0);
					Sign.setImageBitmap(bitmap);
					saveBitmapFile(bitmap,5);
					mPathView.clear();
					util.HideAlert();
				}
			});
			signa_center.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View view) {
					mPathView.clear();
					util.HideAlert();
				}
			});
			dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
			dialog.show();
			Window window = dialog.getWindow();
			WindowManager.LayoutParams lp = window.getAttributes();
			WindowManager windowManager = getWindowManager();
			Display display = windowManager.getDefaultDisplay();
			lp.width = display.getWidth();
			dialog.getWindow().setAttributes(lp);
			dialog.getWindow().setContentView(sign);//自定义布局应该在这里添加，要在dialog.show()的后面
		}
		//班组
		public void ShowAlert() {
			initView();
			dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
			dialog.show();
			Window window = dialog.getWindow();
			WindowManager.LayoutParams lp = window.getAttributes();
			WindowManager windowManager = getWindowManager();
			Display display = windowManager.getDefaultDisplay();
			lp.width = display.getWidth();
			dialog.getWindow().setAttributes(lp);
			dialog.getWindow().setContentView(depar);//自定义布局应该在这里添加，要在dialog.show()的后面
		}
		//岗位类型
        public void ShowJobe() {
            initJobe();
            dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
            dialog.show();
            Window window = dialog.getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            WindowManager windowManager = getWindowManager();
            Display display = windowManager.getDefaultDisplay();
            lp.width = display.getWidth();
            dialog.getWindow().setAttributes(lp);
            dialog.getWindow().setContentView(jobe);//自定义布局应该在这里添加，要在dialog.show()的后面
        }
        //工种
        public void ShowWork() {
            initWork();
            dialog.getWindow().setGravity(Gravity.BOTTOM);//可以设置显示的位置
            dialog.show();
            Window window = dialog.getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            WindowManager windowManager = getWindowManager();
            Display display = windowManager.getDefaultDisplay();
            lp.width = display.getWidth();
            dialog.getWindow().setAttributes(lp);
            dialog.getWindow().setContentView(work);//自定义布局应该在这里添加，要在dialog.show()的后面
        }
        //隐藏
		public void HideAlert(){
			dialog.dismiss();
		}

		//血型选择
		public void initLoop(){
			loop_list = (ListView) loop.findViewById(R.id.loot_list);
			String [] group ={"A","B","AB","O","RH阳性","RH阴性"};
			final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mCtx, R.layout.group_item, R.id.group_item,group );
			loop_list.setAdapter(adapter);
			loop_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
					blood_group.setText(loop_list.getItemAtPosition(i).toString());
					HideAlert();

				}
			});
		}
		//班组/部门
		public void initView(){
			dep_list = (ListView) depar.findViewById(R.id.dep_list);
			String [] InfoArray = InfoData.toArray(new String[InfoData.size()]);
			final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mCtx, R.layout.dep_list_item, R.id.dep_list_item,InfoArray );
			dep_list.setAdapter(adapter);
			dep_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
					InfoValue = InfoCode.toArray(new String[InfoCode.size()])[i];//选择的value
					bzbm.setText(dep_list.getItemAtPosition(i).toString());
					HideAlert();

				}
			});
		}
        public void initJobe(){
            jobe_list = (ListView) jobe.findViewById(R.id.jobe_list);
			String [] JobeArray = JobeData.toArray(new String[JobeData.size()]);
            final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mCtx, R.layout.jobe_type_item, R.id.jobe_type_item, JobeArray);
            jobe_list.setAdapter(adapter);
			jobe_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
					try {
						JobeValue = JobeCode.getJSONObject(i).optString("value");
					} catch (JSONException e) {
						e.printStackTrace();
					}
					gwlx.setText(jobe_list.getItemAtPosition(i).toString());
					HideAlert();

                }
            });
        }
        public void initWork(){
            work_list = (ListView) work.findViewById(R.id.work_list);
			String [] WorkArray = WorkData.toArray(new String[WorkData.size()]);
            final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mCtx, R.layout.work_type_item, R.id.work_type_item, WorkArray);
			work_list.setAdapter(adapter);
			work_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
					try {
						WorkValue = WorkCode.getJSONObject(i).optString("value");
					} catch (JSONException e) {
						e.printStackTrace();
					}
					gz.setText(work_list.getItemAtPosition(i).toString());
					HideAlert();

                }
            });
        }
	}
	private void showInfoToast(String info) {
		mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_INFO, info));
	}
}
